package com.mida.app.report.service;

import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.mida.app.report.vo.TemplateImageAndOrgUrlVo;
import com.mida.dms.mdm.pojo.auto.MsdResourceInfo;
import com.mida.dms.mdm.vo.provider.BaseOrgInfoVo;
import com.mida.tool.common.result.ListResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

import static com.mida.tool.common.result.BaseResult.buildListSuccess;

/**
 * @ClassName: DocStructTemplateServiceImpl
 * @Description: TODO
 * @Author: wang xiao le
 * @Date: 2021/8/9 13:59
 **/
@Service
public class DocStructTemplateServiceImpl implements DocStructTemplateService {
    //模板底图
    public static final long TEMPLATE_TYPE = 48790955096014848L;
    @Autowired
    private MdmService mdmService;

    @Override
    public ListResult<TemplateImageAndOrgUrlVo> queryTemplateImageAndOrgUrl(Long orgInfoSoid) {
        ListResult<TemplateImageAndOrgUrlVo> listResult = new ListResult<>();
        TemplateImageAndOrgUrlVo templateImageAndOrgUrlVo = new TemplateImageAndOrgUrlVo();
        //查询模板底图
        List<String> fullImagePathList = queryTemplateImagePathList();
        templateImageAndOrgUrlVo.setFullImagePathList(fullImagePathList);
        //查询医院logo
        String logoUrl = queryHospitalLogo(orgInfoSoid);
        templateImageAndOrgUrlVo.setOraUrl(logoUrl);
        buildListSuccess(listResult, templateImageAndOrgUrlVo);
        return listResult;
    }

    /**
     * @return java.lang.String 医院logoUrl
     * @Author WXL
     * @Description 查询医院logo
     * @Date 2021/8/9
     * @Param [orgInfoSoid] 医院soid
     **/
    private String queryHospitalLogo(Long orgInfoSoid) {
        String logoUrl = null;
        ListResult<BaseOrgInfoVo> orgByOrgInfoSoid = mdmService.findOrgByOrgInfoSoid(orgInfoSoid, false);
        if (ObjectUtils.isNotEmpty(orgByOrgInfoSoid)) {
            //补充医院logo
            logoUrl = orgByOrgInfoSoid.getData().getLogoUrl();

        }
        return logoUrl;
    }

    /**
     * @return java.util.List<java.lang.String> 模板底图url集合
     * @Author WXL
     * @Description 查询模板底图
     * @Date 2021/8/9
     * @Param []
     **/
    private List<String> queryTemplateImagePathList() {
        List<String> fullImagePathList = new ArrayList<>();
        List<Long> imageTypeList = new ArrayList<>();
        imageTypeList.add(TEMPLATE_TYPE);
        ListResult<List<MsdResourceInfo>> listByMediaImageType = mdmService.findListByMediaImageType(imageTypeList);
        List<MsdResourceInfo> data = listByMediaImageType.getData();
        if (ObjectUtils.isNotEmpty(data)) {
            //补充模板底图
            data.forEach(vo -> fullImagePathList.add(vo.getFullImagePath()));
        }
        return fullImagePathList;
    }
}
